<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>{{ taskDate.assessName }}</span>
        <span class="el-dropdown-link" style="font-size: 20px">
            ({{phaseLabel}})
        </span>
      </div>
      <div>
        <el-row>
          <el-col :span="24">
              <h3 class="h2Bold" style="margin-bottom: 30px">基本情况</h3>
          </el-col>
          <el-col :span="24">
            <div style="width: 90%;margin: auto">
              <el-descriptions :column="4" border>
                <el-descriptions-item label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    姓名
                  </template>
                  {{ pat.patientName }}
                </el-descriptions-item>
                <el-descriptions-item label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    性别
                  </template>
                  {{ gender }}
                </el-descriptions-item>
                <el-descriptions-item label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    年龄
                  </template>
                  {{ pat.patientAge }}
                </el-descriptions-item>
                <el-descriptions-item label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    身份证号
                  </template>
                  {{ pat.patientIdentityNo }}
                </el-descriptions-item>
                <el-descriptions-item :span="4" label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    病情摘要
                  </template>
                  {{ clinicData.illnessSummary }}
                </el-descriptions-item>
                <el-descriptions-item :span="4" label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    既往史
                  </template>
                  {{ clinicData.preHistory }}
                </el-descriptions-item>
                <el-descriptions-item :span="4" label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    诊断
                  </template>
                  {{ clinicData.preDiagnose }}
                </el-descriptions-item>
                <el-descriptions-item :span="2" label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    评定人
                  </template>
                  {{ taskDate.doctorName }}
                </el-descriptions-item>
                <el-descriptions-item :span="2" label-style="color:black;background:#f9f9f9" content-style="color:black;">
                  <template slot="label">
                    评定日期
                  </template>
                  {{ assessTime.slice(0,10) }}
                </el-descriptions-item>
              </el-descriptions>
            </div>
          </el-col>

          <el-col>
            <div v-for="(item,index) in comList" :key=index>
              <h3 class="h2Bold">{{ item.titleName }}</h3>
              <div class="containerClass">
                <el-row v-for="(assname,index) in item.assConfig" :key="index" :assname="assname">
                  <el-col :span="22" :offset="1">
                    <keep-alive>
                      <component
                        :is="assname"
                        class="atguigu1"
                        :istrans="true"
                        :fromdata="fromdata[assname]"
                      ></component>
                    </keep-alive>
                  </el-col>
                </el-row>
              </div>
            </div>
          </el-col>
        </el-row>
      </div>
    </el-card>
    <el-card class="box-card">
      <div class="card-title">
        <span>推荐治疗方案</span>
      </div>
      <el-divider class="el-divider"></el-divider>
      <div class="text">
        {{recommendScheme}}
      </div>
    </el-card>
    <el-footer style="display: flex;justify-content: center;" >
      <el-button @click="auditSuccess" type="primary" style="height:40px ">审核通过</el-button>
      <el-button @click="auditFail" style="height:40px;background:#fa964a;color: #FFFFFF; ">审核不通过</el-button>
      <el-button style="height:40px " @click="fanhui">返 回</el-button>
    </el-footer>
  </div>
</template>

<script>
import {getAssess} from "@/api/gaoxin/assess";
import {listData, updateData} from "@/api/gaoxin/data";
import {getTask, updateTask} from "@/api/gaoxin/taskdata";
import {getClinic, listClinicbyone} from "@/api/gaoxin/clinic";
import {getPatient} from "@/api/gaoxin/patient";
import dayjs from "@/api/gaoxin/dayjs.min";
import {addPerformance} from "@/api/gaoxin/performance";

export default {
  name: "assessAudit",
  created() {
    const taskId = Number(this.$route.params.id);
    this.taskId = taskId;
    let query = {taskId: taskId};
    listData(query).then(response => {
      let assData = response.rows[0];
      this.fromdata = assData;
      this.phase = assData.phase;
      this.recommendScheme=assData.recommendScheme
      this.queryParams.auditOpinion = assData.auditOpinion;
      this.queryParams.dataId = assData.dataId;
      this.phaseLabel = this.phase == '1' ? "初期" : this.phase == '2' ? "中期" : this.phase == '3' ? "末期" : "";
      this.quzhuanyi();

      getTask(taskId).then(response => {
        this.taskDate = response.data;
        if(this.taskDate.assessTime){
          this.assessTime=this.taskDate.assessTime
        }
        this.comList = JSON.parse(this.taskDate.assessConfig);
        let clinicId = this.taskDate.clinicId;
        getClinic(clinicId).then(response => {
          let clinic = response.data;
          this.clinicData = response.data;
          // console.log('clinic:',clinic)
          let patientId = clinic.patientId;
          getPatient(patientId).then(response => {
            this.pat = response.data;
          });
        });
      });
    });
  },

  data() {
    return {
      assessTime: '',
      taskId: '',
      phase: '',
      recommendScheme:'',
      phaseLabel: '评定阶段',
      // 数据项
      fromdata: {},
      clinicData: {},
      pat: {},
      taskDate: {},
      clinicList: [],
      assessname: '',
      assessId: '',
      assdata: {},
      assess: {},
      loading: false,
      comList: [],
      doctorname: '',
      queryParams:{
        dataId:'',
        auditOpinion:'',
        status:3
      },
      queryParamsAss: {
        pageNum: 1,
        pageSize: 10,
        source: null,
        preDiagnose: null,
        manageId: null,
        firstDoctorId: null,
        secondDoctorId: null,
        illnessSummary: null,
        preHistory: null,
        familyHistory: null,
        disease: null,
        department: null,
        ward: null,
        bedNum: null,
        createTime: null,
        outTime: null,
        patientId: null,
        status: null
      },
    }
  },
  computed: {
    gender(){
      if(this.clinicData.patientGender === '0') return '男'
      if(this.clinicData.patientGender === '1') return '女'
      if(this.clinicData.patientGender === '2') return '未知'

    },
  },
  methods: {
    getData(){
      this.loading = true;
      listClinicbyone(this.queryParamsAss).then(response => {
        this.clinicList = response.rows;
        this.pat = this.clinicList[0];
        this.total = response.total;
        this.loading = false;
      });
    },
    fanhui(){
      this.$tab.closePage();
      this.$router.go(-1);
    },
    quzhuanyi() {
      var temp=this.fromdata.assessData;
      var reg=/\\/g;
      let replaceAfter = temp.toString().replace(reg,'');
      this.fromdata=JSON.parse(replaceAfter)
    },
    getass() {
      getAssess(this.assessId).then(res => {
        this.assess = res.data;
        this.comList = JSON.parse(this.assess.assessConfig);
      })
    },

    /** 审核通过按钮 */
    auditSuccess(){
      updateData(this.queryParams).then(response => {
        this.$modal.msgSuccess("审核结果提交成功");
      }).then(response => {
        updateTask({taskId: this.taskId, status: 3});
        //添加绩效信息-评定审核
        addPerformance({taskId: this.taskId, performCategory: '3'});
      });
      this.$tab.closePage();
      this.$router.go(-1);
    },
    /** 审核不通过按钮 */
    auditFail() {
      this.$prompt('请填写审核不通过的原因：','提示', {
        confirmButtonText: '提交',
        cancelButtonText: '取消',
        inputType:'textarea',
        inputValidator: (value) => {
          if(!value) {
            return '原因不能为空！';
          }
        },
      }).then(({value})=>{
        updateData({dataId:this.queryParams.dataId,auditOpinion: value,status:5}).then(response => {
          updateTask({taskId: this.taskId, status: 5});
          //添加绩效信息-评定审核
          addPerformance({taskId: this.taskId, performCategory: '3'});
          this.$modal.msgSuccess("审核意见提交成功");
        })
        this.$tab.closePage();
        this.$router.go(-1);
      })

    },
  }
}
</script>

<style scoped>

.box-card{
  width: 78%;
  margin: 20px auto;
  letter-spacing:0.1em;
}
.text {
  font-size: 17px;
  margin-bottom: 16px;
}
.card-title {
  font-weight: 500;
  font-size: 20px;
}

.clearfix {
  font-size: 32px;
  font-weight: 500;
  text-align: center;
}

.basicCondition .el-row{
  margin-bottom: 20px;
}
.h2Bold {
  font-weight: 600;
  margin: 30px 0 0 0;
}
.containerClass {
  min-height: 80px;
  /*padding: 20px 0;*/
}
.atguigu1 {
  pointer-events: none;
}
.el-radio-group {
  pointer-events: none;
}
.el-radio /deep/ .el-radio__label{
  font-size: 20px !important;
}

.el-dropdown-link {
  font-size: 20px;
  margin-left: 20px;
  color: #409EFF;
}
.el-divider {
  margin: 12px 0 20px;
}

</style>
